package com.decent.text;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.decent.entity.Brand;
import com.decent.entity.FbTest;
import com.decent.entity.Order;
import com.decent.entity.ProductShelves;
import com.decent.enums.ExceptionEnum;
import com.decent.enums.StockSheetTypeEnum;
import com.decent.util.Md5;
import com.decent.vo.ProductQuestionVO;
import com.decent.vo.StockSheetCountVO;
import com.github.stuxuhai.jpinyin.PinyinException;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static com.decent.text.Method.getPersonList;

/**
 * @author 王雪杰
 * @date 2021/5/8 10:51
 */
public class Text {

    private static Boolean aBoolean;

    static void test() {
        System.out.println("\n\n\n\n\n\n\n");
        int w = Integer.parseInt("01") + 1;
        System.out.println(w);
        String format = String.format("%02d", w);
        System.out.println(format);


        String substring = "0000".substring(2);
        System.out.println(substring);
    }

    static void test1() {
        String s = "null";
        String[] split = s.split(",");
        System.out.println(Arrays.toString(split) + "  " + split.length);

        String json = "{1,2}";
        System.out.println(Arrays.toString(json.substring(1, json.length() - 1).split(",")));

        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        System.out.println(list.toString());
        JSONArray objects = new JSONArray();
        objects.add(list);
        System.out.println(objects.toString());

        System.out.println(JSON.toJSONString(list));
        String json1 = "[1,2]";
        List<String> list1 = JSONArray.parseArray(json1, String.class);
        System.out.println(list1);

    }

    static void test0505() {
        String json = "[&quot;巧乐兹&quot;,&quot;米其林轮胎&quot;]";
        String json1 = "[\"巧乐兹\",\"米其林轮胎\"]";
        String json2 = "1,2,";

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("brand", json);
        String s = jsonObject.toJSONString();
        System.out.println(s);
        List<String> list = JSONArray.parseArray(json1, String.class);
        System.out.println(list);

        String s1 = json.replaceAll("&quot;", "\"");
        System.out.println(s1);

//        List<Integer> integers = JSONArray.parseArray(json2, Integer.class);
//        System.out.println(integers);

        String[] split = json2.split(",");
        System.out.println(Arrays.toString(split) + "--" + split.length);

        Person person = new Person();
        person.id = 1;
        person.name = "asd";
        String s2 = JSON.toJSONString(person);
        System.out.println("s2:" + s2);
        System.out.println("s2.2:" + JSONObject.toJSONString(person));
        Person parse = JSONObject.parseObject(s2, Person.class);
        Person person1 = null;
        System.out.println("nullTest:" + JSON.toJSONString(person1));
        System.out.println(parse.name);
        Brand brand = new Brand();
        brand.setBrandName("aaa");
        brand.setAttribute("ccc");
        brand.setIconUrl("baidu.com");
        System.out.println(JSON.toJSONString(brand));
    }

    static void jsonTest() {
        String s = "[{\"answers\":[{\"banned\":false,\"id\":6,\"name\":\"在我店购买-10元\",\"reducePrice\":10.00,\"tips\":{\"picUrl\":\"http://dx-pub-test.oss-cn-beijing.aliyuncs.com/dumas/TIP_PIC/2021-06-22/32240183735916825\",\"tipText\":\"\"},\"tipsData\":\"{\\\"picUrl\\\":\\\"http://dx-pub-test.oss-cn-beijing.aliyuncs.com/dumas/TIP_PIC/2021-06-22/32240183735916825\\\",\\\"tipText\\\":\\\"\\\"}\",\"type\":\"TEXT\"}],\"id\":1,\"name\":\"来源选择\",\"questionType\":\"SINGLECHOISE\",\"required\":true},{\"answers\":[{\"id\":11,\"name\":\"国行\",\"reducePrice\":0.00}],\"id\":5,\"name\":\"版本\",\"questionType\":\"SINGLECHOISE\",\"required\":true},{\"answers\":[{\"banned\":false,\"id\":15,\"name\":\"日文20\",\"reducePrice\":20.00,\"type\":\"TEXT\"}],\"id\":6,\"name\":\"语言\",\"questionType\":\"SINGLECHOISE\"},{\"answers\":[{\"id\":16,\"name\":\"包装完好\",\"reducePrice\":0.00}],\"id\":7,\"name\":\"包装是否完好\",\"questionType\":\"SINGLECHOISE\"}]";
        List<ProductQuestionVO> questionVOS = JSONArray.parseArray(s, ProductQuestionVO.class);
        System.out.println(questionVOS.get(0).getAnswers());
    }

    static void test0506() {
        ArrayList<String> list = new ArrayList<>();
        list.add("aaa");
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        List<String> list1 = list.stream().distinct().collect(Collectors.toList());
        System.out.println(list1);
    }


    public static String uuid() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static long textUUID() {
        long start = System.currentTimeMillis();
        System.out.println(uuid());
        long end = System.currentTimeMillis();

        return -(start - end);
    }

    public static void testUUIDTime() throws IllegalAccessException, InstantiationException {
        test0506();
        System.out.println(Text.class.newInstance().hashCode());
        String zhongDi = "重地";
        String tongHuang = "通话";
        long start = System.currentTimeMillis();
        for (int i = 0; i < 5; i++) {
            long l = textUUID();
            System.out.println(l);
        }
        long end = System.currentTimeMillis();
        System.out.println(-(start - end));
    }

    public static void enums() {
        ExceptionEnum insertCardError = ExceptionEnum.INSERT_CARD_ERROR;
        System.out.println(insertCardError.getCode());
    }

    public static void streamText() {
        List<Order> orders = new ArrayList<>();
        orders.add(new Order());
        List<String> strings = orders.stream().map(Order::getOrderNo).collect(Collectors.toList());
    }

    public static void intTest() {
        Integer i = 145;
        Integer i1 = 145;
        System.out.println(i.equals(i1));
    }

    static class Person {
        Integer id;
        String name;
        BigDecimal amount;
        List<Person> people;

        public Integer getId() {
            return id;
        }

        public Person() {
        }

        public Person(Integer id, String name) {
            this.id = id;
            this.name = name;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
            Person person = (Person) o;
            return Objects.equals(id, person.id);
        }

        @Override
        public int hashCode() {
            return Objects.hash(id);
        }

        @Override
        public String toString() {
            return "Person{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    ", amount=" + amount +
                    ", people=" + people +
                    '}';
        }
    }

    public static void setTest() {
        Person person = new Person();
        Person person1 = new Person();
        person.id = 1;
        person.name = "11";
        person1.id = 1;
        person1.name = "22";
        Set<Person> people = new HashSet<>();
        people.add(person);
        people.add(person1);
        people.forEach(System.out::println);
    }

    public static void none() {
        long t0 = System.nanoTime();
        long t1 = System.nanoTime();
        long millis = TimeUnit.NANOSECONDS.toMillis(t1 - t0);
        System.out.println(String.format("sequential sort took: %d ms", millis));
        System.out.println(t0);
        System.out.println(System.currentTimeMillis());
        System.out.println((System.currentTimeMillis() + "").length());

    }

    public static void streamCountTest() {
        Person person = new Person();
        Person person1 = new Person();
        Person person2 = new Person();
        person.id = 1;
        person.name = "11";
        person1.id = 3;
        person1.name = "22";
        person2.id = 3;
        person1.name = "22";
        ArrayList<Person> people = new ArrayList<>();
        people.add(person);
        people.add(person1);
        people.add(person2);
        int sum = people.stream().mapToInt(Person::getId).distinct().sum();
        System.out.println(sum);
    }

    public static void testMap() {
        HashMap<Long, String> map = new HashMap<>();
        map.put(1L, "1L");
        map.put(2L, "2L");
        String s = map.get(3L);
        boolean b = map.containsKey(null);
        System.out.println(b);
    }

    public static void testLength() {
        String str = new String("a,./");
        System.out.println(str.length());
    }

    public static void testOptionalMap() {
        Person person = new Person();
        person.id = 1;
        System.out.println(Optional.ofNullable(person).map(person1 -> person1.id + 1).orElse(0));
    }

    public static void listAddIndex() {
        List<Person> personList = getPersonList();
        personList.add(0, new Person());
        System.out.println(personList.get(0).id);

    }

    public static void testSwitchNull() {
        ExceptionEnum error = null;
        switch (error) {
            case INSERT_CARD_ERROR:
                System.out.println("1");
                break;
            default:
                System.out.println("0");
        }
    }

    public static void TestEnumNull() {
        ExceptionEnum error = null;
        if (ExceptionEnum.INSERT_CARD_ERROR.equals(error)) {
            System.out.println("1");
        } else {
            System.out.println("0");
        }
    }

    public static void localDateTest() {
//     LocalDateTimeUtils#  begin  end
        LocalDate date = LocalDate.of(2021, 7, 9);
        LocalDateTime of = LocalDateTime.of(null == date ? LocalDate.now() : date, LocalTime.MIN);
        System.out.println(of);
    }

    public static void localDateTimeTest1() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstday = date.with(TemporalAdjusters.firstDayOfMonth());
        LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
        System.out.println("firstday:" + firstday);
        System.out.println("lastDay:" + lastDay);

    }

    public static void localDateTest2() {
        LocalDateTime dateTime = LocalDateTime.now();
//获取月的第一天
        LocalDateTime firstDay = dateTime.with(TemporalAdjusters.firstDayOfMonth());
//获取月的最后一天
        LocalDateTime lastDay = dateTime.with(TemporalAdjusters.lastDayOfMonth());
//获取月的第一天0时0分0秒
        LocalDateTime firstDay1 = dateTime.with(TemporalAdjusters.firstDayOfMonth())
                .withHour(0).withMinute(0).withSecond(0).withNano(0);
//获取月的最后一天的23点59分59秒
        LocalDateTime lastDay1 = dateTime.with(TemporalAdjusters.lastDayOfMonth())
                .withHour(23).withMinute(59).withSecond(59);
        System.out.println(firstDay);
        System.out.println(lastDay);
        System.out.println(firstDay1);
        System.out.println(lastDay1);
    }

    public static void localDateTimeNowTest() {
        System.out.println(LocalDate.now());
    }

    public static void localDateTimeTest2() {
        LocalDate date = LocalDate.of(2021, 7, 15);
        LocalDateTime of = LocalDateTime.of(null == date ? LocalDate.now() : date, LocalTime.MIN);
        System.out.println(Duration.between(of, LocalDateTime.now()).toMinutes());
    }

    public static void toFyhTest() {
        ArrayList<String> list = new ArrayList<>();
        ProductShelves productShelves = ProductShelves.builder().shelvesName("aa").layers(3).columns(3).build();
        IntStream.rangeClosed(1, productShelves.getLayers())
                .forEach(i -> IntStream.rangeClosed(1, productShelves.getColumns()).forEach(j -> {
                    list.add(String.format("%s-%d-%d", productShelves.getShelvesName(), i, j));
                }));
        // dao.batchInsert()
        System.out.println(list);

    }

    public static void collectionTest() {
        ArrayList<String> list = new ArrayList<>();
        boolean notEmpty = CollectionUtils.isEmpty(list);
        System.out.println(notEmpty);
    }

    public static void stringUtilsJoin() {
        ArrayList<Long> list = new ArrayList<>();
        list.add(1L);
        list.add(2L);
        list.add(3L);
        Long[] l = (Long[]) Arrays.asList(1L, 2L).toArray();
        System.out.println(StringUtils.join(l, ","));
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("1L");
        list1.add("2L");
        list1.add("3L");
//        System.out.println(list1.stream().map(Long::parseLong).collect(Collectors.joining(",")));

    }

    public static void toFyhTest2() {
        List<StockSheetCountVO> list = new ArrayList<>();
        list.add(StockSheetCountVO.builder().sheetType(StockSheetTypeEnum.IN).dealNum(1L).unDealNum(1L).finishNum(1L).build());
        list.add(StockSheetCountVO.builder().sheetType(StockSheetTypeEnum.BUY).dealNum(1L).unDealNum(1L).finishNum(1L).build());
        Arrays.stream(StockSheetTypeEnum.values())
                .filter(stockSheetTypeEnum -> !StockSheetTypeEnum.SALE.equals(stockSheetTypeEnum))
                .forEach(stockSheetTypeEnum -> {
                    boolean anyMatch = list.stream().anyMatch(stockSheetCountVO -> stockSheetTypeEnum.equals(stockSheetCountVO.getSheetType()));
                    if (!anyMatch) {
                        list.add(StockSheetCountVO.builder().sheetType(stockSheetTypeEnum).dealNum(0L).unDealNum(0L).finishNum(0L).build());
                    }
                });
        System.out.println(list);
    }

    public static void streamFilterTest() {
        List<Person> personList = getPersonList();
        Text.Person person = new Text.Person();
        person.name = "11";
        personList.add(person);
        System.out.println(personList.stream().map(Person::getId).filter(Objects::nonNull).collect(Collectors.toList()));
    }

    public static void stringSplitLength() {
        String s = "1";
        System.out.println(s.split(",").length);
    }

    public static void longToIntegerTest() {
        Integer a = null;
        System.out.println(a);
    }

    public static void regTest() {
        final String STR_ENG_PATTERN = "^[0-9,]+$";
        final String STR_ENG_PATTERN_1 = "^(?!,)[0-9,]+(?<!,)$";
        String str = "1,3";
        System.out.println(str.matches(STR_ENG_PATTERN));
    }

    public static void longTest() {
        Long a = null;
        Long b = null;
        System.out.println(a.equals(b));
    }

    public static void mapTest() {
        HashMap<String, Integer> map = new HashMap();
        Integer asd = map.put("asd", 1);
        Integer zxc1 = map.put("zxc", 2);
        Integer zxc = map.put("zxc", 3);
        System.out.println(asd);
        System.out.println(zxc1);
        System.out.println(zxc);
        System.out.println(map);
        ArrayList<String> list = new ArrayList<>();
        list.add("aaaa");
        list.add("zzzz");
        list.add("xxxx");
        System.out.println(list.contains("xxxxs"));
    }

    public static void listToSet() {
        ArrayList<String> list = new ArrayList<>();
        list.add("aaaa");
        list.add("zzzz");
        list.add("xxxx");
        list.add("xxxx");
        System.out.println(new HashSet<>(list));
        Stream.of("aa").collect(Collectors.toList());
    }

    public static void stringUtilsTest() {
        String s = "   ";
        System.out.println(StringUtils.isBlank(s));
    }

    public static void testClazz() throws NoSuchFieldException, IllegalAccessException {
        Person person = new Person();
        person.name = "aa";
        person.id = 1;
        Class<Person> personClass = Person.class;
        Field name = personClass.getDeclaredField("name");
        System.out.println(name.get(person));
    }

    public static void testClazz2() {
        FbTest fbTest = new FbTest();
        fbTest.setDay1(1);
        Class<FbTest> aClass = FbTest.class;
        Field[] fields = aClass.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            try {
                if (Objects.isNull(field.get(fbTest))
                        && Integer.class.getTypeName().equals(field.getType().getTypeName())) {
                    field.set(fbTest, 0);
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        System.out.print(fbTest + "\n");
    }

    public static void hashMapTest() {
        HashMap<String, String> map = new HashMap<>(3);
        map.put("11", "11");
        map.put("22", "22");
        map.put(null, "33");
        System.out.println(map.get(null));
        System.out.println(map.get("asdzxc"));
        System.out.println(map.getOrDefault("66", "xcv"));
    }

    public static void stringContains() {
        String str = "1,5,2,3";
        Long productId = 2L;
        System.out.println(str.contains(String.valueOf(productId)));
    }

    public static void listStreamTest() {
        ArrayList<Person> strings = new ArrayList<>();
        strings.stream().filter(person -> Objects.nonNull(person.id)).forEach(System.out::println);
        System.out.println("strings: " + strings);
        Person person = new Person();
        Person person1 = new Person();
        Person person2 = new Person();
        person.id = 1;
        person.name = "11";
        person1.id = 3;
        person1.name = "22";
        person2.id = 3;
        person2.name = "22";
        ArrayList<Person> people = new ArrayList<>();
        people.add(person);
        people.add(person1);
        people.add(person2);
        people.add(new Person());
        System.out.println(people.stream().filter(person3 -> person3.id != 5).collect(Collectors.toList()));
    }

    public static void listIndex() {
        List<Person> personList = getPersonList();
//        Iterator<Person> iterator = personList.iterator();
//        while (iterator.hasNext()) {
//            Person next = iterator.next();
//            if (next.id > 1) {
//                iterator.
//            }
//        }
        for (int value = 0; value <= personList.size() - 1; value++) {
            if (personList.get(value).id > 1) {
                Person person = personList.get(value);
                person.id -= 1;
                personList.add(value, personList.get(value));
            }
        }
        System.out.println(personList);
    }

    public static void streamAnyMatchTest() {
        List<Person> personList = getPersonList();
        ArrayList<Person> people = new ArrayList<>();
        Text.Person person1 = new Text.Person();
        person1.amount = BigDecimal.ZERO;
        System.out.println(people.stream().anyMatch(person -> {
            System.out.println("a");
            return person.id == 1;
        }));
        System.out.println("aa:" + people.stream().map(person -> person.amount).reduce(BigDecimal.ZERO, BigDecimal::add));
    }

    public static void integerLengthTest() {
        Integer a = 1234567890;
        a *= 10;
        System.out.println(a);

    }

    public static void memoryTest() {
        Person person = new Person();
        person.name = "1";
        String a = person.name;
        person.name = "2";
        System.out.println(a);
    }

    public static void enumEqualsTest() {
        System.out.println(ExceptionEnum.INSERT_CARD_ERROR == (null));
    }

    public static void uuidTest() {
        System.out.println(UUID.randomUUID());
    }

    public static Long getCurrentTime() {
        long l = System.currentTimeMillis();
        System.out.println(l);
        return l;
    }

    public static void get4Random() {
        int num = 1;
        Random random = new Random();
        num = num << 4 + random.nextInt();
        System.out.println(num);
    }

    public static void md5() {
        System.out.println(Md5.getMd5("1234?", true, StandardCharsets.UTF_8.name()));
    }

    public static void jdSubString() {
        String traceMark = "配送员：张三已出发，手机号：15150000006，请您准备好全套商品、发票及包装，感谢您的配合！";
        System.out.println(traceMark.substring(4, traceMark.indexOf("已出发")));
        System.out.println(traceMark.substring(traceMark.indexOf("手机号：") + 4, traceMark.indexOf("，请您准备好全套商品")));

        String trackMark1 = "取件完成,运单号:VY0000000001";
        System.out.println(trackMark1.substring(trackMark1.indexOf("运单号:") + 4));
    }

    public static void md5HashTest() {
        String s1 = "通话";
        String s2 = "重地";
        String md51 = Md5.getMd5(s1, true, StandardCharsets.UTF_8.name());
        String md52 = Md5.getMd5(s2, true, StandardCharsets.UTF_8.name());
        System.out.println(md51 + "\n" + md52);
        System.out.println(s1.hashCode() == s2.hashCode());
    }

    public static void randomTest() {
        System.out.println(RandomStringUtils.randomAlphanumeric(8));
    }

    public static void stringUtilsEquals() {
        String s1 = null;
        String s2 = "";
        System.out.println(StringUtils.equals(s1, s2));
    }

    public static void replaceTest() {
        String shipTime = "";
        System.out.println(shipTime.replace("T", " "));
    }

    public static void regTest1() {
        String bankCardNoPattern = "^([1-9])(\\d{14}|\\d{18})$";
        String a = "6214835359063359";
        System.out.println(a.matches(bankCardNoPattern));
    }

    public static void addAllTest() {
        List<Person> personList = getPersonList();
        personList.addAll(personList);
        personList.addAll(personList);
        personList.addAll(personList);
        System.out.println(personList);
        System.out.println(personList.size());
    }

    public static void distinctTest() {
        List<Person> personList = getPersonList();
        personList.addAll(personList);
        Person person = new Person();
        person.id = 8;
        personList.add(person);
        System.out.println(personList.stream().distinct().collect(Collectors.toList()));
    }

    public static void stringMemoryTest() {
        StringBuilder string = new StringBuilder();
        stringMemoryTest(string);
        System.out.println("asd" + string);
    }

    public static void stringMemoryTest(StringBuilder string) {
        string.append("hahaha");
    }

    public static void nullJSONTest() {
        String a = "{\"code\":\"19\"," +
                "\"enDesc\":\"Invalid access_token(Solution reference: https://jos.jd.com/commondoc?listId=171)\"," +
                "\"msg\":\"" +
                "       {\\\"error_response\\\": " +
                "               {\\\"code\\\":\\\"19\\\"," +
                "               \\\"zh_desc\\\":\\\"token已过期或者不存在，请重新授权,access_token:b09e080db8a54926a6782ef28237a12ciyja（解决方案参考: https://jos.jd.com/commondoc?listId=171）\\\"," +
                "               \\\"en_desc\\\":\\\"Invalid access_token(Solution reference: https://jos.jd.com/commondoc?listId=171)\\\"}}\"," +
                "\"url\":\"https://api.jd.com/routerjson?access_token=b09e080db8a54926a6782ef28237a12ciyja&app_key=6C14B64E6815BFE6E45F38B7FDDFA0DA&method=jingdong.ldop.receive.pickuporder.receive&v=2.0&sign=1D3B96D2D03573D8AEF6D34AE33FCB7E&timestamp=2021-10-06+11%3A49%3A15.042%2B0800&360buy_param_json={\\\"allowedRepeatOrderType\\\":0,\\\"antiTearingCode\\\":null,\\\"backAddress\\\":\\\"山东省烟台市莱山区飞龙天润大厦1705\\\",\\\"customerCode\\\":\\\"010K1349070\\\",\\\"customerContract\\\":\\\"茶蛋卡带\\\",\\\"customerTel\\\":\\\"18561109735\\\",\\\"desp\\\":\\\"游戏卡带\\\",\\\"freightSettleType\\\":0,\\\"guaranteeSettleType\\\":0,\\\"guaranteeValue\\\":null,\\\"guaranteeValueAmount\\\":null,\\\"orderId\\\":\\\"202110061149150927266693\\\",\\\"packingSettleType\\\":0,\\\"pickupAddress\\\":\\\"河北省石家庄市桥西区红旗街道 汇丰西路29号河北外国语学院\\\",\\\"pickupEndTime\\\":\\\"2021-10-07 11:00:00\\\",\\\"pickupName\\\":\\\"王成洋\\\",\\\"pickupStartTime\\\":\\\"2021-10-07 09:00:00\\\",\\\"pickupTel\\\":\\\"18632222511\\\",\\\"productCount\\\":\\\"1\\\",\\\"productId\\\":null,\\\"productName\\\":\\\"游戏卡带\\\",\\\"promiseTimeType\\\":1,\\\"remark\\\":\\\"无\\\",\\\"skuAddService\\\":null,\\\"skuCheckAttachFile\\\":null,\\\"skuCheckOutShapes\\\":null,\\\"snCode\\\":null,\\\"valueAddService\\\":null,\\\"volume\\\":120.0,\\\"weight\\\":1.0}\"," +
                "\"zhDesc\":\"token已过期或者不存在，请重新授权,access_token:b09e080db8a54926a6782ef28237a12ciyja（解决方案参考: https://jos.jd.com/commondoc?listId=171）\"}";
    }

    public static void joinTest() {
        ArrayList<String> strings = new ArrayList<>();
        strings.add("asd");
        strings.add("qwer");
        strings.add("ZXC");
        System.out.println(StringUtils.join(strings, ","));
    }

    public static void optionalTest() {
        String s = null;
        System.out.println(Optional.ofNullable(s).orElse("asd"));
    }

    public static void localDateTimeTest() {
        String startTime = "2021-10-11 09:00:00";
        String endTime = "2021-10-11 10:00:00";
        // 指定模式
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 将字符串格式化为 LocalDateTime
        LocalDateTime startLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
        LocalDateTime endLocalDateTime = LocalDateTime.parse(endTime, dateTimeFormatter);
        // 剩余天数
        //int lastDayInt = (int) (endDate.toEpochDay() - startDate.toEpochDay());
        //System.out.println("1:" + lastDayInt);
        System.out.println(Duration.between(startLocalDateTime, endLocalDateTime).toDays());
        // 加天数
        System.out.println(startLocalDateTime.plusDays(90));
        // 获得今天在今年的天数
        System.out.println("获得今天在今年的天数:" + LocalDateTime.now().getDayOfYear());
        System.out.println("获得今年天数:" + LocalDate.now().lengthOfYear());
    }

    public static void pinyinTest() throws PinyinException {
        String name = "     NS塞尔达";
        String name1 = "😄";
        String name2 = String.valueOf(((char) 0));
        String name3 = "";
        String name4 = "重要";
        String name41 = "重复";
        String name5 = "银行";
        String name51 = "行动";

        String name1Pinyin = PinyinHelper.getShortPinyin(name1.trim());
        System.out.println("name:" + PinyinHelper.getShortPinyin(name.trim()).charAt(0));
        System.out.println("name1:" + name1Pinyin + "\\" + name1.length() + "\\" + name1Pinyin.length() + "\\" + (int) name1.charAt(0));
        System.out.println("name2:" + PinyinHelper.getShortPinyin(name2.trim()));
        System.out.println("name3:" + PinyinHelper.getShortPinyin(name3.trim()));
        System.out.println("name4:" + PinyinHelper.getShortPinyin(name4.trim()).charAt(0));
        System.out.println("name4_1:" + PinyinHelper.getShortPinyin(name41.trim()).charAt(0));
        System.out.println("name5:" + PinyinHelper.getShortPinyin(name5.trim()).charAt(1));
        System.out.println("name51:" + PinyinHelper.getShortPinyin(name51.trim()).charAt(0));
    }

    public static void charTest() throws PinyinException {
        String name = "a";

        System.out.println(name.compareToIgnoreCase("C"));
        System.out.println(name.compareTo("C"));
    }

    public static void regexTest() {
        String pattern = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$";
        System.out.println("a1234asad".matches(pattern));
    }

    public static void regexTest2() {
        String s = "、s";
        System.out.println(s.matches("^[a-zA-Z]+$"));
    }

    public static void grouping() {
        List<Person> personList = getPersonList();
        System.out.println(personList.stream().collect(Collectors.groupingBy(Person::getId, Collectors.counting())));
    }

    public static void mapMemoryTest() {

        HashMap<Integer, List<Person>> map = new HashMap<>();
        map.put(1, new ArrayList<Person>() {
            {
                add(new Person(1, "1asd"));
                add(new Person(1, "1zxc"));
            }
        });
        map.put(2, new ArrayList<Person>() {
            {
                add(new Person(2, "2asd"));
                add(new Person(2, "2zxc"));
            }
        });
        List<Person> people = map.get(1);
        Person person = people.get(0);
        person.name = "zzz";
        System.out.println(map);
    }

    public static void _test() {
        int a = 4__1__0;
        System.out.println(a);
    }

    public static void foreachTest() {
        ArrayList<Person> people = new ArrayList<>();
        people.forEach(person -> {
            System.out.println(people);
        });
        System.out.println(people.stream().sorted(Comparator.comparing(Person::getId)).collect(Collectors.toList()));
        Iterator<Person> iterator = people.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }

    private static final Person PERSON1 = new Person(1, "asd");

    public static void stringMeTest() {
        Person person3 = PERSON1;
        person3.amount = BigDecimal.TEN;
        System.out.println(PERSON1);
        System.out.println(person3);
    }

    public static void stringReplace() {
        String s = "SPS4PS5NS 怒之铁拳4 年度版";
        String s1 = s.replaceFirst("NS|PS4|PS5", "");
        System.out.println(s1 + "\n" + s);
        // System.out.println(s.replaceFirst("NS", "").replaceFirst("PS", ""));
    }

    public static void filePathTest() {
        String fileName = Objects.requireNonNull(Text.class.getClassLoader().getResource("pdfTest/测试pdf.pdf")).getPath();//获取文件路径
        String fileUtl = Objects.requireNonNull(Text.class.getResource("/pdfTest/测试pdf.pdf")).getFile();
        String path = ClassLoader.getSystemResource("").getPath();
        System.out.println(fileName);
        System.out.println(fileUtl);
        System.out.println(path);
    }

    public static void deleteFile() {
        File file = new File("D:\\idea\\workspace\\test-4-7\\src\\main\\resources\\pdfTest\\15-15-15-59_test.pdf");
        file.deleteOnExit();
    }

    public static void stringSplitTest() {
        String a = "aaa    ssss dddd";
        String s = a.replaceAll("[ ]+", ",");
        System.out.println(s);
        System.out.println(Arrays.toString(s.split(" ")));
        // System.out.println(s[1].length());
    }

    public static void foreachTest1() {
        ArrayList<String> strings = new ArrayList<>();
        strings.forEach(s -> {
            System.out.println("qqqq");
        });
        ArrayList<String> strings1 = new ArrayList<>();
        strings.forEach(s -> {
            System.out.println("qqqq");
        });

    }

    public static void printString() {
        StringBuilder a = new StringBuilder();
        StringBuilder s = new StringBuilder();
        a.append(RandomStringUtils.randomAlphanumeric(2000));
        s.append(RandomStringUtils.randomAlphanumeric(500));
        System.out.println(a.length());
        System.out.println(a);
        System.out.println(s.length());
        System.out.println(s);

    }

    public static void arraysAsList() {
        List<String> strings = Arrays.asList("111111111111111", "22222222222222", "333333333333333");
        ArrayList<String> exist = new ArrayList<>();
        exist.add("22222222222222");
        ArrayList<String> strings2 = new ArrayList<>();
        strings2.add("111111111111111");
        strings2.add("22222222222222");
        strings2.add("333333333333333");
        strings2.removeAll(exist);
        System.out.println(strings2);
    }


    public static void main(String[] args) throws Exception {
        localDateTest2();
    }

}
